package com.astudio.lhasa.workers.ai.map;

import android.os.Handler;

import com.astudio.lhasa.workers.ai.map.interfaces.IMapAroundSearchCallback;
import com.astudio.lhasa.workers.ai.map.modules.MapLocation;

import java.util.List;

public abstract class BaseVendorMap {

    Handler mHandler = new Handler();

    public abstract void init();
    public abstract void start();
    public abstract void terminate();
    public abstract MapLocation getLocation();
    public abstract List<MapLocation> searchAroundLocked(String key, int limit);

    public void searchAroundAsync(final String key, final int limit, final IMapAroundSearchCallback callback){
        if (callback == null) {
            return;
        }

        if (getLocation() == null) {
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    searchAroundAsync(key, limit, callback);
                }
            }, 1000);
            return;
        } else {
            callback.OnResult(searchAroundLocked(key, limit));
        }
    }
}
